<template>
  <div
    id="radarChart"
    ref="radarChart"
    :style="{ width: props.width, height: props.height }"
  ></div>
</template>
<script lang="ts" setup>
import * as echarts from "echarts";
import { EChartsOption, EChartsType } from "echarts";
import { onMounted, onUnmounted, ref } from "vue";

const radarChart = ref(null);
const props = defineProps({
  width: {
    type: String,
    default: "100%",
  },
  height: {
    type: String,
    default: "100%",
  },
  config: {
    default: {},
  },
});
// 线性表的配置项
const option = ref<EChartsOption>({
  ...props.config,
  legend: {
    data: ["Allocated Budget", "Actual Spending"],
  },
  radar: {
    // shape: 'circle',
    indicator: [
      { name: "Sales", max: 25000 },
      { name: "Administration", max: 25000 },
      { name: "Information Technology", max: 25000 },
      { name: "Customer Support", max: 25000 },
      { name: "Development", max: 25000 },
      { name: "Marketing", max: 25000 },
    ],
  },
  series: [
    {
      type: "radar",
      data: [
        {
          value: [12000, 3000, 20000, 15000, 10000, 1000],
          name: "Allocated Budget",
        },
        {
          value: [10000, 14000, 22000, 25000, 22000, 1000],
          name: "Actual Spending",
        },
      ],
    },
  ],
});

const initChart = () => {
  const myChart: EChartsType = echarts.init(radarChart.value!);
  myChart.setOption(option.value);
  window.addEventListener("resize", () => myChart.resize());
};

onMounted(() => {
  initChart();
});
onUnmounted(() => {
  window.addEventListener("resize", null);
});
</script>
<style lang="less" rel="stylesheet/less" scoped></style>
